package com.byb.server.service.mapper;

import com.byb.server.domain.*;
import com.byb.server.service.dto.ProductDTO;

import org.mapstruct.*;

/**
 * Mapper for the entity Product and its DTO ProductDTO.
 */
@Mapper(componentModel = "spring", uses = {IsurerMapper.class, TypesOfInsuranceMapper.class, WordKeyMapper.class, })
public interface ProductMapper extends EntityMapper <ProductDTO, Product> {

    @Mapping(source = "insurer.id", target = "insurerId")
    @Mapping(source = "insurer.corporateName", target = "insurerCorporateName")

    @Mapping(source = "typesOfInsurance.id", target = "typesOfInsuranceId")
    @Mapping(source = "typesOfInsurance.typesOfInsuranceName", target = "typesOfInsuranceTypesOfInsuranceName")
    ProductDTO toDto(Product product); 

    @Mapping(source = "insurerId", target = "insurer")

    @Mapping(source = "typesOfInsuranceId", target = "typesOfInsurance")
    Product toEntity(ProductDTO productDTO); 
    default Product fromId(Long id) {
        if (id == null) {
            return null;
        }
        Product product = new Product();
        product.setId(id);
        return product;
    }
}
